package com.coreJava.shejimoshi.dongtaidaili;

import java.lang.reflect.Proxy;

/**
 * 作者: LCG
 * 日期: 2020/2/13 19:52
 * 描述:
 */
public class TestDongTaiLi {

    public static void main(String[] args) {

        //为一个接口创建代理对象
        /*TInvocationhandler tInvocationhandler = new TInvocationhandler();
        Class<?>[] interfaces = {TmyInterface.class};
        TmyInterface tmyInterface = (TmyInterface) Proxy.newProxyInstance(TmyInterface.class.getClassLoader(),interfaces, tInvocationhandler);
        tmyInterface.test();*/

        //也可以为一个类创建戴笠对对象增强类方法的功能，但是要求这个类必须要有接口

        TmyInterfaceImpl tmyInterface = new TmyInterfaceImpl();
        Tinvocationimpl<TmyInterface> tinvocationimpl=new Tinvocationimpl<>(tmyInterface);
        TmyInterface tmyInterface1=(TmyInterface)Proxy.newProxyInstance(TmyInterface.class.getClassLoader(), TmyInterfaceImpl.class.getInterfaces(), tinvocationimpl);

        System.out.println(tmyInterface1.test());
    }
}
